package larrys.pomodoro.daoimpl.rowmappers;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

import larrys.pomodoro.domain.entity.Round;

import org.springframework.jdbc.core.RowMapper;

public class RoundRowMapper implements RowMapper<Round> {

	@Override
	public Round mapRow(ResultSet rs, int index) throws SQLException {
		long id = rs.getLong("id");
		int duration = rs.getInt("duration");
		Date startTime = rs.getTimestamp("start_time");
		Date endTime = rs.getTimestamp("end_time");
		boolean interrupted = rs.getBoolean("interrupted");
		boolean finished = rs.getBoolean("finished");
		String comment = rs.getString("comment");
		long userId = rs.getLong("user_id");
		long activityId = rs.getLong("activity_id");
		Round round = new Round(id, userId, activityId, finished);
		round.setStartTime(startTime);
		round.setEndTime(endTime);
		round.setDuration(duration);
		round.setInterrupted(interrupted);
		round.setComment(comment);
		return round;
	}

}
